package lcr;

public class Test0181 {
}

class Solution0181_1 {
    public String reverseMessage(String message) {
        int length = message.length();
        char[] chars = message.toCharArray();
        StringBuilder builder = new StringBuilder();

        for (int i = length-1; i >= 0; i--) {
            char c = chars[i];
            if (c==' '){
                continue;
            }

            int index = i;
            while (index>=0 && chars[index]!=' '){
                index--;
            }
            if (builder.length() > 0) builder.append(' ');

            builder.append(message, index+1, i+1);
            i=index;
        }

        return builder.toString();
    }
}
